package com.yhd.mapper;

import com.yhd.domain.Account;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author 二十
 * @since 2021/11/30 10:33 下午
 */
public interface AccountMapper {

    /**
     * 查询账户信息
     */
    @Select("select * from account")
    @Results(id = "accountMap",
            value = {
                    @Result(id = true, column = "id", property = "id"),
                    @Result(column = "uid", property = "uid"),
                    @Result(column = "money", property = "money"),
                    @Result(column = "uid",
                            property = "user",
                            one = @One(select = "com.yhd.mapper.UserMapper.findById",
                                    fetchType = FetchType.LAZY))
            })
    List<Account> findAll();

    /**
     * 根据id查询
     */
    @Select("select * from account where uid=#{uid}")
    Account findById(Integer id);
}
